<?php

class GalactusModelControl extends GalactusModelGallery {

	function __construct($control) {
		GalactusModel::__construct($control);
	}

	public function getAzAlt($callback, $telescope_id) {
		$telescope = reset($this->retrieveTelescope($telescope_id));
		$content = file_get_contents($telescope["link_control"].'/?callback='.$callback.'&u='.$this->control->user_id.'&c=0');
		header('Content-Type: application/json');
		echo $content;
	}

	public function getRaDec($callback, $telescope_id) {
		$telescope = reset($this->retrieveTelescope($telescope_id));
		$content = file_get_contents($telescope["link_control"].'/?callback='.$callback.'&u='.$this->control->user_id.'&c=1');
		header('Content-Type: application/json');
		echo $content;
	}

	public function gotoAzAlt($params) {
	}

	public function gotoRaDec($callback, $telescope_id, $params) {
		$telescope = reset($this->retrieveTelescope($telescope_id));
		$content = file_get_contents($telescope["link_control"].'/?callback='.$callback.'&u='.$this->control->user_id.'&c=3+'.implode('+', $params));
		header('Content-Type: application/json');
		echo $content;
	}

	public function snapshot($params) {
		$filename = '/tmp/snapshot'.$this->control->user_id.'.jpg';
		shell_exec('/usr/local/bin/ffmpeg -y -an -i http://'.$_SERVER["HTTP_HOST"].':8090/camera'.$params[0].'.mjpeg -ss 00:00:05 -vframes 1 '.$filename);
		$this->addContent(file_get_contents($filename), 'jpg', $params[1], $params[2], $params[3], $params[4]);
		$content = reset($this->retrieveContent(NULL, $this->control->user_id));
		$date = new DateTime($content["created_on"]);
		echo '
			<li class="thumbnail span2">
					<img src="data:image/jpg;base64,'.base64_encode(file_get_contents($filename)).'" />
					<table class="table table-bordered table-condensed table-info">
						<tr><th colspan="2"><button type="button" class="close" value="'.$content["id"].'">×</button>'.$date->format("d/m/Y H:i:s").'</th></tr>
						<tr><th>RA</th><th>DEC</th></tr>
						<tr><td>'.$params[1].'</td><td>'.$params[2].'</td></tr>
						<tr><th>AZ</th><th>ALT</th></tr>
						<tr><td>'.$params[3].'</td><td>'.$params[3].'</td></tr>
					</table>
				</div>
			</li>
		';
	}

}

?>
